#include <iostream>
#include <string>
#include "user.pb.h"
#include "mprpcapplication.h"
#include "rpcprovider.h"
#include "logger.h"
using namespace fixbug;
//rpc service provider
class UserService:public UserServiceRpc
{
public:
    bool Login(std::string name,std::string pwd)
    {
        std::cout<<"login doing"<<std::endl;
        return true;
    }

    bool Register(int32_t userid,std::string password)
    {
        std::cout<<"Register doing"<<std::endl;
        return true;
    }

    void Login(::google::protobuf::RpcController* controller,
                       const ::fixbug::LoginRequest* request,
                       ::fixbug::LoginResponse* response,
                       ::google::protobuf::Closure* done)
    {
        std::string name=request->name();
        std::string pwd=request->pwd();
        bool login_res=Login(name,pwd);

        ResultCode* code=response->mutable_result();
        code->set_errcode(1);
        code->set_errmsg("");
        response->set_success(login_res);

        done->Run();
    }

    void Register(::google::protobuf::RpcController* controller,
                    const ::fixbug::RegisterRequest* request,
                    ::fixbug::RegisterResponse* response,
                    ::google::protobuf::Closure* done)
    {
        int32_t userid=request->userid();
        std::string pwd=request->pwd();
        bool Register_res=Register(userid,pwd);

        ResultCode* code=response->mutable_result();
        code->set_errcode(1);
        code->set_errmsg("");
        response->set_success(Register_res);

        done->Run();
    }
private:

};

int main(int argc,char** argv)
{
    
    
    MrpcApplication::Init(argc,argv);
    LOGGER_INFO("SERVER IS WORKING");
    RpcProvider provider;
    provider.NotifyService(new UserService());
    provider.run();
    return 0;
}